package cn.lzk._01_sync;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;


import java.nio.charset.StandardCharsets;

public class Producer {
    public static void main(String[] args) throws Exception {
        //1.创建生产者
        DefaultMQProducer producer = new DefaultMQProducer("sync_producer");
        //2.设置nameserver地址
        producer.setNamesrvAddr("localhost:9876");
        //开启
        producer.start();
        //3.创建消息体
        Message message = new Message("sync", "hello", "这是我的第二遍作业".getBytes(StandardCharsets.UTF_8));
        //4.发送
        SendResult send = producer.send(message);
        System.out.println(send);
        //5.关闭生产者
        producer.shutdown();
    }
}
